import request from '@/utils/request'
import { encryptionData } from '@/utils/com'
import Qs from 'qs'

/* 员工-列表 */
export function getUserList(data) {
  return request({
    url: '/jcdSys/user/userPage',
    method: 'get',
    headers: encryptionData(data, '/user/userPage'),
    params: data
  })
}

/* 员工-添加 */
export function addUser(data) {
  return request({
    url: '/jcdSys/user/addUserRole',
    method: 'post',
    headers: encryptionData(data, '/user/addUserRole'),
    data: Qs.stringify(data)
  })
}

/* 员工-修改 */
export function updUser(data) {
  return request({
    url: '/jcdSys/user/updateUserRole',
    method: 'post',
    headers: encryptionData(data, '/user/updateUserRole'),
    data: Qs.stringify(data)
  })
}

/* 员工-开启禁用 */
export function setUserFlag(data) {
  return request({
    url: '/jcdSys/user/editUserRole',
    method: 'post',
    headers: encryptionData(data, '/user/editUserRole'),
    data: Qs.stringify(data)
  })
}

/* 员工-密码重置 */
export function resetUserPsd(data) {
  return request({
    url: '/jcdSys/user/resetUserPwd',
    method: 'post',
    headers: encryptionData(data, '/user/resetUserPwd'),
    data: Qs.stringify(data)
  })
}

/* 员工-删除 */
export function delUser(data) {
  return request({
    url: `/jcdSys/user/delete/${data.id}`,
    method: 'delete',
    headers: encryptionData({}, `/user/delete/${data.id}`),
    data: Qs.stringify({})
  })
}

/* 角色-列表 */
export function getRoleList(data) {
  return request({
    url: '/jcdSys/role/page',
    method: 'get',
    headers: encryptionData(data, '/role/page'),
    params: data
  })
}

/* 角色-添加 */
export function addRole(data) {
  return request({
    url: '/jcdSys/role/add',
    method: 'post',
    headers: encryptionData(data, '/role/add'),
    data: Qs.stringify(data)
  })
}

/* 角色-修改 */
export function updRole(data) {
  return request({
    url: '/jcdSys/role/update',
    method: 'put',
    headers: encryptionData(data, '/role/update'),
    data: Qs.stringify(data)
  })
}

/* 角色-删除 */
export function delRole(data) {
  return request({
    url: `/jcdSys/role/delete/${data.id}`,
    method: 'delete',
    headers: encryptionData({}, `/role/delete/${data.id}`),
    data: Qs.stringify({})
  })
}

/* 菜单-列表 */
export function getMenuList(data) {
  return request({
    url: '/jcdSys/resource/tree',
    method: 'get',
    headers: encryptionData(data, '/resource/tree'),
    params: data
  })
}

/* 菜单-根据角色获取列表 */
export function getMenuByRoleList(data) {
  return request({
    url: `/jcdSys/resource/tree/${data.id}`,
    method: 'get',
    headers: encryptionData({}, `/resource/tree/${data.id}`),
  })
}

/* 菜单-设置角色菜单 */
export function setMenuByRoleList(data) {
  return request({
    url: '/jcdSys/role/saveRoleMenus',
    method: 'post',
    headers: encryptionData(data, '/role/saveRoleMenus'),
    data: Qs.stringify(data)
  })
}

/* 菜单-添加 */
export function addMenu(data) {
  return request({
    url: '/jcdSys/resource/add',
    method: 'post',
    headers: encryptionData(data, '/resource/add'),
    data: Qs.stringify(data)
  })
}

/* 菜单-修改 */
export function updMenu(data) {
  return request({
    url: '/jcdSys/resource/update',
    method: 'put',
    headers: encryptionData(data, '/resource/update'),
    data: Qs.stringify(data)
  })
}
